package org.dizena.modules.wss.bean;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.IndexDirection;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;

@NoArgsConstructor
@Data
@Document(collection = "wss_message")
@CompoundIndexes({@CompoundIndex(name = "idx_receiver_sender", def = "{'receiver': 1,'sender': 1}")})
public class Message implements Serializable, Comparable<Message>
{
    private static final long serialVersionUID = 6104176307322002860L;
    private String id;
    /**
     * text image file audio video loc
     */
    private String type;
    private String content;
    private String sender;
    private String receiver;

    /**
     * 图片，评论，视频 链接
     */
    private String linkId;
    private String fileName;
    private Long fileSize;
    private Double[] loc;
    private String locStr;

    private Integer imStatus;
    /**
     * 送达时间
     */
    private Long arriveTime;
    /**
     * 已读时间
     */
    private Long readTime;
    /**
     * 消息创建时间
     */
    @Indexed(direction = IndexDirection.DESCENDING)
    private Long createTime;

    public Message(String sender, String receiver, String content)
    {
        this.sender = sender;
        this.receiver = receiver;
        this.content = content;
        this.type = "text";
    }

    @Override
    public int compareTo(Message o)
    {
        Long res = this.createTime - o.getCreateTime();
        return res.intValue();
    }

}